package com.example.b_308.software.controller.user;

import com.example.b_308.software.R;

import com.example.b_308.software.comment.view.title.util.Globel;
import com.example.b_308.software.comment.view.title.util.StringValidators;
import com.example.b_308.software.controller.BaseController;
import com.example.b_308.software.model.Company;
import com.example.b_308.software.model.Staff;
import com.example.b_308.software.service.IUserView;
import com.example.b_308.software.service.UserService;

/**
 * Created by B-308 on 2017/11/28.
 */
public class UserController extends BaseController {
    IUserView iUserView;
    UserService userService;

    public UserController(IUserView iUserView) {
        this.iUserView = iUserView;
        userService=new UserService(iUserView);

    }

    public  void login(String phone, String password){
        //验证手机号码
        if(StringValidators.isEmply(phone)){
            iUserView.fail(Globel.getString(R.string.password_error));
return;
        }
        //验证密码
        if(password.length()<6||password.length()>13){
            iUserView.fail(Globel.getString(R.string.password_error));
            return;

        }
        Staff staff=new Staff();
        staff.setPhone(phone);
        staff.put("password",password);
        userService.login(staff);
    }
    public void register(Company company,Staff staff){
        staff.putAttrs(company);
        userService.register(staff);

    }
    public void getCode(String phone){
        if(!StringValidators.isNotEmply(phone)){
            iUserView.fail(Globel.getString(R.string.password_error));
            return;
        }
        Staff staff=new Staff();
        staff.setPhone(phone);
        userService.getCode(staff);
    }
}
